package com.atguigu.lease.common.Exceptions;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author zy
 * @Date 2024/12/10
 * @Desc
 * @Version 1.0
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(LeaseException.class)
    public Result leaseExceptionHandler(LeaseException e) {
        e.printStackTrace();
        int code = e.getCode();
        String message = e.getMessage();
        return Result.build(code,message);
    }


    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }
}
